mod core;

use wasm_bindgen::prelude::*;

#[cfg(feature = "console_error_panic_hook")]
fn set_panic_hook() {
    console_error_panic_hook::set_once();
}

#[cfg(not(feature = "console_error_panic_hook"))]
fn set_panic_hook() {}

/// Initialise internal state once the module is loaded.
#[wasm_bindgen(start)]
pub fn initialize() {
    set_panic_hook();
}

/// Evaluate the implicit function at (x, y).
#[wasm_bindgen]
pub fn evaluate_expression(expression: &str, x: f64, y: f64) -> Result<f64, JsValue> {
    core::evaluate(expression, x, y).map_err(|err| JsValue::from_str(&err.to_string()))
}
